-----------------------------------------------------------------------------
-- 菊花waitIng
--
---------------
-- Author: 筱迪
-- Date: 2020.12.23
-----------------------------------------------------------------------------
UIWaiting = {}

local waitInstance = nil
local isDelayShow = false	--是否延迟显示菊花图标
local delayShowTime = 1000	--延迟显示菊花图标的时间
local countDownTimer = nil	--显示菊花图标的倒计时
local typeCtrl = nil

------------------对外接口  设置显示/隐藏------------------
function UIWaiting.ShowWaiting(code)
	--UIWaiting.InstanceWaiting()
    --
	--UIWaiting.SetIsShow(true)
end

function UIWaiting.HideWaiting(code)
	--if UIWaiting.CheckIsShow() then
	--	UIWaiting.SetIsShow(false)
	--end
end

function UIWaiting.WaitingShow(isDelay)
	if logicMgr.GuildBattleManager.isLoginSceneServer() or RedRob.ClientBattle.IsInBattle() then
		return
	end
	isDelayShow = isDelay
	UIWaiting.InstanceWaiting()
	UIWaiting.SetIsShow(true)
end

function UIWaiting.WaitingHide()
	if UIWaiting.CheckIsShow() then
		UIWaiting.SetIsShow(false)
	end
end

--- 如果客户端重登后需要清资源 这个接口要手动调用
function UIWaiting.ClearInstanceWaiting()
	waitInstance = nil
end

------------------私有函数-----------------------
function UIWaiting.InstanceWaiting()
	if not waitInstance then
		local name, package = getUIName(PanelResNames.UIWaiting)
		panelMgr:ShowUI(name, package, UIWaiting.OnCreate, Config.useLocalUI)
	end
end

function UIWaiting.OnCreate(obj)
	waitInstance = obj
	typeCtrl = obj:GetController("type")
	typeCtrl.selectedIndex = 1;
end
function UIWaiting.OnDestroy()
	waitInstance = nil
	if countDownTimer then
		utimer.remove(countDownTimer)
		countDownTimer = nil
	end
end
function UIWaiting.CheckIsShow()
	if waitInstance and waitInstance.visible then
		return true
	end
	return false
end

function UIWaiting.SetIsShow(is)
	if waitInstance then
		waitInstance.visible = is
		if is then
			if isDelayShow then
				typeCtrl.selectedIndex = 0;
				if countDownTimer then
					utimer.remove(countDownTimer)
					countDownTimer = nil
				end
				countDownTimer = utimer.delayCall(function()
					typeCtrl.selectedIndex = 1;
				end,delayShowTime)
			end
		end
	end
end

return UIWaiting